# -*- coding:utf-8 -*-
"""

@File : kafkaConsumer.py

@Author: 爸爸

@Date : 2019/7/26

@Desc :
"""
import json
import time

from kafka import KafkaConsumer


def main():
    consumer = KafkaConsumer(bootstrap_servers='127.0.0.1:9092',
                             #group_id='test12542',
                             # group_id='test1223',  # Sim kfk
                             group_id='station12345',  # auto
                             value_deserializer=lambda m: json.loads(m.decode('utf8')),
                             api_version=(0, 10),
                             # auto_offset_reset='earliest',
                             )
    consumer.subscribe(['ShareCheckInfo', 'ShareDevStatus'])
    with open('kfkConsumer.txt', 'a+') as f:
        for msg in consumer:
            print(msg.topic, msg.offset, msg.value)
            f.write("{} {} {}\r\n".format(msg.topic, msg.offset, msg.value))
            f.flush()
            # time.sleep(1)


if __name__ == '__main__':
    main()
